package com.visikard.ui.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.visikard.item.NewItemTransactionHistory;
import com.visikard.ui.R;
import com.visikard.utility.BitmapUtils;
import com.visikard.utility.UILImageUtils;

public class NewTransactionHistoryAdapter extends ArrayAdapter<NewItemTransactionHistory> {

	public NewTransactionHistoryAdapter(Context context, List<NewItemTransactionHistory> objects) {
		super(context, R.layout.item_trans_hostory_new, objects);
	}

	public NewTransactionHistoryAdapter(Context context, int resource, List<NewItemTransactionHistory> objects) {
		super(context, resource, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (convertView == null) {
			view = LayoutInflater.from(getContext()).inflate(R.layout.item_trans_hostory_new, parent, false);
			Holder holder = new Holder();
			holder.imgAvatar = (ImageView) view.findViewById(R.id.img_avatar);
			holder.txtContent = (TextView) view.findViewById(R.id.txt_content);
			view.setTag(holder);
		}

		Holder holder = (Holder) view.getTag();
		NewItemTransactionHistory item = getItem(position);

		UILImageUtils.loadImage(holder.imgAvatar, // image view
				item.getAvatar(), // url
				1, // size of view
				BitmapUtils.ROUND_ALL, // round all
				4, // round size
				3, // shadow
				R.drawable.kard_shadow_default_horizontal, // shadow resource
				0, 0);

		holder.txtContent.setText(Html.fromHtml(item.getContentHtml(getContext().getResources())));

		return view;
	}

	private class Holder {
		ImageView imgAvatar;
		TextView txtContent;
	}

}
